package com.huage_07.lesson_02;

import java.io.*;

public class CopyMp4Demo {
    public static void main(String[] args)throws IOException {

        long start = System.currentTimeMillis();
        System.out.println("开始");
//        method1();//共耗时296706毫秒
//        method2();//共耗时453毫秒
//        method3();//共耗时464毫秒
        method4();//共耗时109毫秒
        System.out.println("结束");
        long end = System.currentTimeMillis();
        System.out.println("共耗时"+(end-start)+"毫秒");
    }
    //基本字节流一次读写一个字节
    public static void method1()throws IOException {
        FileInputStream fis = new FileInputStream("D:\\document\\movies\\歌唱社会主义祖国.mp4");
        FileOutputStream fos = new FileOutputStream("class1\\src\\com\\huage_07\\lesson_02\\歌唱社会主义祖国.mp4");

        int by;
        while ((by=fis.read())!=-1){
            fos.write(by);
        }

        fis.close();
        fos.close();
    }
    //基本字节流一次读写一个字节数组
    public static void method2()throws IOException {
        FileInputStream fis = new FileInputStream("D:\\document\\movies\\歌唱社会主义祖国.mp4");
        FileOutputStream fos = new FileOutputStream("class1\\src\\com\\huage_07\\lesson_02\\歌唱社会主义祖国.mp4");

        byte[] bytes = new byte[1024];
        int len;
        while ((len=fis.read(bytes))!=-1){
            fos.write(bytes,0,len);
        }

        fis.close();
        fos.close();
    }
    //缓冲字节流一次读写一个字节
    public static void method3()throws IOException{
        BufferedInputStream bis = new BufferedInputStream(new FileInputStream("D:\\document\\movies\\歌唱社会主义祖国.mp4"));
        BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream("class1\\src\\com\\huage_07\\lesson_02\\歌唱社会主义祖国.mp4"));

        int by;
        while ((by=bis.read())!=-1){
            bos.write(by);
        }

        bis.close();
        bos.close();
    }
    //缓冲字节流一次读写一个字节数组
    public static void method4()throws IOException{
        BufferedInputStream bis = new BufferedInputStream(new FileInputStream("D:\\document\\movies\\歌唱社会主义祖国.mp4"));
        BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream("class1\\src\\com\\huage_07\\lesson_02\\歌唱社会主义祖国.mp4"));

        byte[] bytes = new byte[1024];
        int len;
        while ((len=bis.read(bytes))!=-1){
            bos.write(bytes,0,len);
        }

        bis.close();
        bos.close();
    }
}
